package cn.org.zx.notebook.ctrl;

import java.io.IOException;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.multiaction.MultiActionController;

import cn.org.zx.notebook.blh.NoteBookBlh;
import cn.org.zx.common.aop.BeanFactory;
import cn.org.zx.common.commutils.Json;
import cn.org.zx.common.commutils.StringUtils;

public class NoteBookCtrl extends MultiActionController{
	private NoteBookBlh notebookblh;
		
	public NoteBookCtrl(){
		notebookblh = (NoteBookBlh)BeanFactory.getBean(new NoteBookBlh());	
	}
	
	//查找记录记事本记录
	public ModelAndView getNoteBookQueryList(HttpServletRequest request,HttpServletResponse response) throws IOException {
		request.setCharacterEncoding("utf-8");
		response.setCharacterEncoding("utf-8");
		
		
		Map mapData = request.getParameterMap();
		Map mapReturn = notebookblh.getNoteBookQueryList(mapData);
		
		PrintWriter out = null;
		try {
			out = response.getWriter();
			String result = Json.toJson(mapReturn);
			out.print(result);
		} catch (IOException e) {
			e.printStackTrace();
		}
		
		return null;
	}
	
	//记事本新增保存
	public ModelAndView getNoteBookCreateSave(HttpServletRequest request,HttpServletResponse response) throws IOException {
		request.setCharacterEncoding("utf-8");
		response.setCharacterEncoding("utf-8");
		
		Map sessionMap = (Map)request.getSession().getAttribute("infodata");		
		String strUserID = StringUtils.toString(sessionMap.get("a_id"));		
		if(strUserID.equals("")) return null;
		
		Map mapData = request.getParameterMap();		
		Map mapReturn = notebookblh.getNoteBookCreateSave(mapData,strUserID);
		
		PrintWriter out = null;
		try {
			out = response.getWriter();
			String result = Json.toJson(mapReturn);
			out.print(result);
		} catch (IOException e) {
			e.printStackTrace();
		}
		return null;
	}
	
	//记事本记录查看
	public ModelAndView getNoteBookView(HttpServletRequest request,HttpServletResponse response) throws IOException {				
		request.setCharacterEncoding("utf-8");
		response.setCharacterEncoding("utf-8");
		
		Map mapData = request.getParameterMap();
		Map mapReturn = notebookblh.getNoteBookView(mapData);
		
		return new ModelAndView("notebook_view.jsp",mapReturn);
	}
	
	//记事本记录删除 
	public ModelAndView getNoteBookDelete(HttpServletRequest request,HttpServletResponse response) throws IOException {
		request.setCharacterEncoding("utf-8");
		response.setCharacterEncoding("utf-8");
		
		Map sessionMap = (Map)request.getSession().getAttribute("infodata");		
		String strUserID = StringUtils.toString(sessionMap.get("a_id"));		
		if(strUserID.equals("")) return null;
		
		Map mapData = request.getParameterMap();		
		Map mapReturn = notebookblh.getNoteBookDelete(mapData,strUserID);
		
		PrintWriter out = null;
		try {
			out = response.getWriter();
			String result = Json.toJson(mapReturn);
			out.print(result);
		} catch (IOException e) {
			e.printStackTrace();
		}
		return null;
	}
	
}
